package commands;

/**
 * Represents a Command to remove a Card from a given Zone
 */
public class RemoveCardCommand extends CardCommand
{
	/**
	 * Default constructor for reflection purposes.
	 */
	public RemoveCardCommand() {
		this(null);
	}

	public RemoveCardCommand(core.Card card) {
		setCard(card);
	}

	public net.StateUpdate execute() throws CommandException
	{
		if (oldZone == null)
			throw new CommandException(this, "Null zone in RemoveCardCommand");
		if (!oldZone.getCards().contains(card))
			throw new CommandException(this, "Zone does not contain card");
		net.StateUpdate stateUpdate = super.execute();
		stateUpdate.addChange(new net.ChildRemoval(oldZone, "card", card));
		return stateUpdate;
	}

	public void setCard(core.Card card) {
		super.setCard(card);
		oldZone = (card == null ? null : card.getZone());
	}

	public String getMessage() {
		return "remove card " + util.Util.prettyPrint(card) + " from " + oldZone;
	}

	private core.Zone oldZone;
}